package model;
import java.sql.*;

import connection.DbConnection;
import bean.PollUser;

public class AddUserImpl {
	private PollUser user;
	
	public AddUserImpl(PollUser user){
		Date currDate = new Date(System.currentTimeMillis());
		System.out.println("Current date:"+currDate.toString());
		this.user = user;
		System.out.println("impl created");
	}
	
	public boolean add(){
		Connection conn = new DbConnection().getConn();
		String sql = "INSERT INTO PollUser(Username, Password, email, genericUser, fname, lname) VALUES (";
		sql += user.getUsername()+", ";
		sql += user.getPassword()+", ";
		sql += user.getEmail()+", ";
		sql += user.getGenericUser()+", ";
		sql += user.getFirstname()+", ";
		sql += user.getLastname()+")";
		
		try{
			System.out.println(sql);
			PreparedStatement ps = conn.prepareStatement(sql);
			ps.executeQuery();
		}catch(SQLException e){
			System.out.println("Bad SQL: adduserimpl");
			return false;
		}

		return true;
	}
}
